home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / compress / unzip531.zip / aosvs / aosvs.c next >
C/C++ Source or Header  |  1997-02-17  |  45KB  |  1,321 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   aosvs.c
  4.  
  5.   AOS/VS-specific routines for use with Info-ZIP's UnZip 5.2 and later.
  6. [GRR:  copied from unix.c -> undoubtedly has unnecessary stuff: delete at will]
  7.  
  8.   Contains:  readdir()
  9.              do_wild()
  10.              open_outfile()
  11.              mapattr()
  12.              mapname()
  13.              checkdir()
  14.              screenlines()
  15.              close_outfile()
  16.              version()             <-- GRR:  needs work!  (Unix, not AOS/VS)
  17.              zvs_create()
  18.              zvs_credir()
  19.              ux_to_vs_name()
  20.              dgdate()
  21.  
  22.   ---------------------------------------------------------------------------*/
  23.  
  24.  
  25. #define UNZIP_INTERNAL
  26. #include "unzip.h"
  27. #include "aosvs/aosvs.h"
  28. #include <packets/create.h>
  29. #include <sys_calls.h>
  30. #include <paru.h>
  31.  
  32. #define symlink(resname,linkname) \
  33.   zvs_create(linkname,-1L,-1L,-1L,ux_to_vs_name(vs_resname,resname),$FLNK,-1,-1)
  34.                                              *  file type */
  35.  
  36. #ifdef DIRENT
  37. #  include <dirent.h>
  38. #else
  39. #  ifdef SYSV
  40. #    ifdef SYSNDIR
  41. #      include <sys/ndir.h>
  42. #    else
  43. #      include <ndir.h>
  44. #    endif
  45. #  else /* !SYSV */
  46. #    ifndef NO_SYSDIR
  47. #      include <sys/dir.h>
  48. #    endif
  49. #  endif /* ?SYSV */
  50. #  ifndef dirent
  51. #    define dirent direct
  52. #  endif
  53. #endif /* ?DIRENT */
  54.  
  55. static int            created_dir;          /* used in mapname(), checkdir() */
  56. static int            renamed_fullpath;     /* ditto */
  57.  
  58. static ZEXTRAFLD      zzextrafld;           /* buffer for extra field containing
  59.                                              *  ?FSTAT packet & ACL buffer */
  60. static char           vs_resname[2*$MXPL];
  61. static char           vs_path[2*$MXPL];     /* buf for AOS/VS pathname */
  62. static char           Vs_path[512];         /* should be big enough [GRR: ?] */
  63. static P_CTIM         zztimeblock;          /* time block for file creation */
  64. static ZVSCREATE_STRU zzcreatepacket;       /* packet for sys_create(), any
  65.  
  66.  
  67. #ifndef SFX
  68. #ifdef NO_DIR                  /* for AT&T 3B1 */
  69.  
  70. #define opendir(path) fopen(path,"r")
  71. #define closedir(dir) fclose(dir)
  72. typedef FILE DIR;
  73.  
  74. /*
  75.  *  Apparently originally by Rich Salz.
  76.  *  Cleaned up and modified by James W. Birdsall.
  77.  */
  78. struct dirent *readdir(dirp)
  79.     DIR *dirp;
  80. {
  81.     static struct dirent entry;
  82.  
  83.     if (dirp == NULL)
  84.         return NULL;
  85.  
  86.     for (;;)
  87.         if (fread(&entry, sizeof (struct dirent), 1, dirp) == 0)
  88.             return (struct dirent *)NULL;
  89.         else if (entry.d_ino)
  90.             return &entry;
  91.  
  92. } /* end function readdir() */
  93.  
  94. #endif /* NO_DIR */
  95.  
  96.  
  97. /**********************/
  98. /* Function do_wild() */   /* for porting:  dir separator; match(ignore_case) */
  99. /**********************/
  100.  
  101. char *do_wild(__G__ wildspec)
  102.     __GDEF
  103.     char *wildspec;         /* only used first time on a given dir */
  104. {
  105.     static DIR *dir = (DIR *)NULL;
  106.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  107.     static int firstcall=TRUE, have_dirname, dirnamelen;
  108.     struct dirent *file;
  109.  
  110.  
  111.     /* Even when we're just returning wildspec, we *always* do so in
  112.      * matchname[]--calling routine is allowed to append four characters
  113.      * to the returned string, and wildspec may be a pointer to argv[].
  114.      */
  115.     if (firstcall) {        /* first call:  must initialize everything */
  116.         firstcall = FALSE;
  117.  
  118.         /* break the wildspec into a directory part and a wildcard filename */
  119.         if ((wildname = strrchr(wildspec, '/')) == (char *)NULL) {
  120.             dirname = ".";
  121.             dirnamelen = 1;
  122.             have_dirname = FALSE;
  123.             wildname = wildspec;
  124.         } else {
  125.             ++wildname;     /* point at character after '/' */
  126.             dirnamelen = wildname - wildspec;
  127.             if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
  128.                 Info(slide, 1, ((char *)slide,
  129.                   "warning:  can't allocate wildcard buffers\n"));
  130.                 strcpy(matchname, wildspec);
  131.                 return matchname;   /* but maybe filespec was not a wildcard */
  132.             }
  133.             strncpy(dirname, wildspec, dirnamelen);
  134.             dirname[dirnamelen] = '\0';   /* terminate for strcpy below */
  135.             have_dirname = TRUE;
  136.         }
  137.  
  138.         if ((dir = opendir(dirname)) != (DIR *)NULL) {
  139.             while ((file = readdir(dir)) != (struct dirent *)NULL) {
  140.                 if (file->d_name[0] == '.' && wildname[0] != '.')
  141.                     continue;  /* Unix:  '*' and '?' do not match leading dot */
  142.                 if (match(file->d_name, wildname, 0)) {  /* 0 == case sens. */
  143.                     if (have_dirname) {
  144.                         strcpy(matchname, dirname);
  145.                         strcpy(matchname+dirnamelen, file->d_name);
  146.                     } else
  147.                         strcpy(matchname, file->d_name);
  148.                     return matchname;
  149.                 }
  150.             }
  151.             /* if we get to here directory is exhausted, so close it */
  152.             closedir(dir);
  153.             dir = (DIR *)NULL;
  154.         }
  155.  
  156.         /* return the raw wildspec in case that works (e.g., directory not
  157.          * searchable, but filespec was not wild and file is readable) */
  158.         strcpy(matchname, wildspec);
  159.         return matchname;
  160.     }
  161.  
  162.     /* last time through, might have failed opendir but returned raw wildspec */
  163.     if (dir == (DIR *)NULL) {
  164.         firstcall = TRUE;  /* nothing left to try--reset for new wildspec */
  165.         if (have_dirname)
  166.             free(dirname);
  167.         return (char *)NULL;
  168.     }
  169.  
  170.     /* If we've gotten this far, we've read and matched at least one entry
  171.      * successfully (in a previous call), so dirname has been copied into
  172.      * matchname already.
  173.      */
  174.     while ((file = readdir(dir)) != (struct dirent *)NULL)
  175.         if (match(file->d_name, wildname, 0)) {   /* 0 == don't ignore case */
  176.             if (have_dirname) {
  177.                 /* strcpy(matchname, dirname); */
  178.                 strcpy(matchname+dirnamelen, file->d_name);
  179.             } else
  180.                 strcpy(matchname, file->d_name);
  181.             return matchname;
  182.         }
  183.  
  184.     closedir(dir);     /* have read at least one dir entry; nothing left */
  185.     dir = (DIR *)NULL;
  186.     firstcall = TRUE;  /* reset for new wildspec */
  187.     if (have_dirname)
  188.         free(dirname);
  189.     return (char *)NULL;
  190.  
  191. } /* end function do_wild() */
  192.  
  193. #endif /* !SFX */
  194.  
  195.  
  196.  
  197.  
  198.  
  199. /***************************/
  200. /* Function open_outfile() */
  201. /***************************/
  202.  
  203. int open_outfile(__G)         /* return 1 if fail */
  204.     __GDEF
  205. {
  206.     int errc = 1;    /* init to show no success with AOS/VS info */
  207.     long dmm, ddd, dyy, dhh, dmin, dss;
  208.  
  209.  
  210. #ifdef DLL
  211.     if (G.redirect_data)
  212.         return redirect_outfile(__G)==FALSE;
  213. #endif
  214.  
  215.     if (stat(G.filename, &G.statbuf) == 0 && unlink(G.filename) < 0) {
  216.         Info(slide, 0x401, ((char *)slide, LoadFarString(CannotDeleteOldFile),
  217.           G.filename));
  218.         return 1;
  219.     }
  220.  
  221. /*---------------------------------------------------------------------------
  222.     If the file didn't already exist, we created it earlier.  But we just
  223.     deleted it, which we still had to do in case we are overwriting an exis-
  224.     ting file.  So we must create it now, again, to set the creation time
  225.     properly.  (The creation time is the best functional approximation of
  226.     the Unix mtime.  Really!)
  227.  
  228.     If we stored this with an AOS/VS Zip that set the extra field to contain
  229.     the ?FSTAT packet and the ACL, we should use info from the ?FSTAT call
  230.     now.  Otherwise (or if that fails), we should create anyway as best we
  231.     can from the normal Zip info.
  232.  
  233.     In theory, we should look through an entire series of extra fields that
  234.     might exist for the same file, but we're not going to bother.  If we set
  235.     up other types of extra fields, or if other environments we run into may
  236.     add their own stuff to existing entries in Zip files, we'll have to.
  237.  
  238.     Note that all the packet types for sys_fstat() are the same size & mostly
  239.     have the same structure, with some fields being unused, etc.  Ditto for
  240.     sys_create().  Thus, we assume a normal one here, not a dir/cpd or device
  241.     or IPC file, & make little adjustments as necessary.  We will set ACLs
  242.     later (to reduce the chance of lacking access to what we create now); note
  243.     that for links the resolution name should be stored in the ACL field (once
  244.     we get Zip recognizing links OK).
  245.   ---------------------------------------------------------------------------*/
  246.  
  247.     if (G.extra_field != NULL) {
  248.         memcpy((char *) &zzextrafld, G.extra_field, sizeof(zzextrafld));
  249.         if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  250.                     sizeof(zzextrafld.extra_header_id))  &&
  251.             !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel),
  252.                     sizeof(zzextrafld.extra_sentinel))
  253.         {
  254.             zzcreatepacket.norm_create_packet.cftyp_format =
  255.               zzextrafld.fstat_packet.norm_fstat_packet.styp_format;
  256.             zzcreatepacket.norm_create_packet.cftyp_entry =
  257.               zzextrafld.fstat_packet.norm_fstat_packet.styp_type;
  258.  
  259.             /* for DIRS/CPDs, the next one will give the hash frame size; for
  260.              * IPCs it will give the port number */
  261.             zzcreatepacket.norm_create_packet.ccps =
  262.               zzextrafld.fstat_packet.norm_fstat_packet.scps;
  263.  
  264.             zzcreatepacket.norm_create_packet.ctim = &zztimeblock;
  265.             zztimeblock.tcth = zzextrafld.fstat_packet.norm_fstat_packet.stch;
  266.  
  267.             /* access & modification times default to current */
  268.             zztimeblock.tath.long_time = zztimeblock.tmth.long_time = -1;
  269.  
  270.             /* give it current process's ACL unless link; then give it
  271.              * resolution name */
  272.             zzcreatepacket.norm_create_packet.cacp = (char *)(-1);
  273.  
  274.             if (zzcreatepacket.norm_create_packet.cftyp_entry == $FLNK)
  275.                 zzcreatepacket.norm_create_packet.cacp = zzextrafld.aclbuf;
  276.  
  277.             zzcreatepacket.dir_create_packet.cmsh =
  278.               zzextrafld.fstat_packet.dir_fstat_packet.scsh;
  279.             if (zzcreatepacket.norm_create_packet.cftyp_entry != $FCPD) {
  280.                 /* element size for normal files */
  281.                 zzcreatepacket.norm_create_packet.cdel =
  282.                   zzextrafld.fstat_packet.norm_fstat_packet.sdeh;
  283.             }
  284.             zzcreatepacket.norm_create_packet.cmil =
  285.               zzextrafld.fstat_packet.norm_fstat_packet.smil;
  286.  
  287.             if ((errc = sys_create(ux_to_vs_name(vs_path, G.filename),
  288.                  &zzcreatepacket)) != 0)
  289.                 Info(slide, 0x201, ((char *)slide,
  290.                   "error creating %s with AOS/VS info -\n\
  291.                   will try again with ordinary Zip info\n", G.filename));
  292.         }
  293.     }
  294.  
  295.     /* do it the hard way if no AOS/VS info was stored or if we had problems */
  296.     if (errc) {
  297.         dmm = (G.lrec.last_mod_file_date >> 5) & 0x0f;
  298.         ddd = G.lrec.last_mod_file_date & 0x1f;
  299.         dyy = (G.lrec.last_mod_file_date >> 9) + 1980;
  300.         dhh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  301.         dmin = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  302.         dss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  303.  
  304.         if (zvs_create(G.filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) |
  305.             (dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1))
  306.         {
  307.             Info(slide, 0x201, ((char *)slide, "error: %s: cannot create\n",
  308.               G.filename));
  309.             return 1;
  310.         }
  311.     }
  312.  
  313.     Trace((stderr, "open_outfile:  doing fopen(%s) for writing\n", G.filename));
  314.     if ((G.outfile = fopen(G.filename, FOPW)) == (FILE *)NULL) {
  315.         Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),
  316.           G.filename));
  317.         return 1;
  318.     }
  319.     Trace((stderr, "open_outfile:  fopen(%s) for writing succeeded\n",
  320.       G.filename));
  321.  
  322. #ifdef USE_FWRITE
  323. #ifdef _IOFBF  /* make output fully buffered (works just about like write()) */
  324.     setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);
  325. #else
  326.     setbuf(G.outfile, (char *)slide);
  327. #endif
  328. #endif /* USE_FWRITE */
  329.     return 0;
  330.  
  331. } /* end function open_outfile() */
  332.  
  333.  
  334.  
  335.  
  336.  
  337. /**********************/
  338. /* Function mapattr() */
  339. /**********************/
  340.  
  341. int mapattr(__G)
  342.     __GDEF
  343. {
  344.     ulg tmp = G.crec.external_file_attributes;
  345.  
  346.     switch (G.pInfo->hostnum) {
  347.         case UNIX_:
  348.         case VMS_:
  349.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  350.             return 0;
  351.         case AMIGA_:
  352.             tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */
  353.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  354.             break;
  355.         /* all remaining cases:  expand MSDOS read-only bit into write perms */
  356.         case FS_FAT_:
  357.         case FS_HPFS_:
  358.         case FS_NTFS_:
  359.         case MAC_:
  360.         case ATARI_:             /* (used to set = 0666) */
  361.         case TOPS20_:
  362.         default:
  363.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  364.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  365.             break;
  366.     } /* end switch (host-OS-created-by) */
  367.  
  368.     /* for originating systems with no concept of "group," "other," "system": */
  369.     umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */
  370.     G.pInfo->file_attr &= ~tmp;
  371.  
  372.     return 0;
  373.  
  374. } /* end function mapattr() */
  375.  
  376.  
  377.  
  378.  
  379.  
  380. /************************/
  381. /*  Function mapname()  */
  382. /************************/
  383.                              /* return 0 if no error, 1 if caution (filename */
  384. int mapname(__G__ renamed)   /*  truncated), 2 if warning (skip file because */
  385.     __GDEF                   /*  dir doesn't exist), 3 if error (skip file), */
  386.     int renamed;             /*  or 10 if out of memory (skip file) */
  387. {                            /*  [also IZ_VOL_LABEL, IZ_CREATED_DIR] */
  388.     char pathcomp[FILNAMSIZ];    /* path-component buffer */
  389.     char *pp, *cp=(char *)NULL;  /* character pointers */
  390.     char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  391.     int quote = FALSE;           /* flags */
  392.     int error = 0;
  393.     register unsigned workch;    /* hold the character being tested */
  394.  
  395.  
  396. /*---------------------------------------------------------------------------
  397.     Initialize various pointers and counters and stuff.
  398.   ---------------------------------------------------------------------------*/
  399.  
  400.     if (G.pInfo->vollabel)
  401.         return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */
  402.  
  403.     /* can create path as long as not just freshening, or if user told us */
  404.     G.create_dirs = (!G.fflag || renamed);
  405.  
  406.     created_dir = FALSE;        /* not yet */
  407.  
  408.     /* user gave full pathname:  don't prepend rootpath */
  409.     renamed_fullpath = (renamed && (*G.filename == '/'));
  410.  
  411.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  412.         return 10;              /* initialize path buffer, unless no memory */
  413.  
  414.     *pathcomp = '\0';           /* initialize translation buffer */
  415.     pp = pathcomp;              /* point to translation buffer */
  416.     if (G.jflag)                /* junking directories */
  417.         cp = (char *)strrchr(G.filename, '/');
  418.     if (cp == (char *)NULL)     /* no '/' or not junking dirs */
  419.         cp = G.filename;        /* point to internal zipfile-member pathname */
  420.     else
  421.         ++cp;                   /* point to start of last component of path */
  422.  
  423. /*---------------------------------------------------------------------------
  424.     Begin main loop through characters in filename.
  425.   ---------------------------------------------------------------------------*/
  426.  
  427.     while ((workch = (uch)*cp++) != 0) {
  428.  
  429.         if (quote) {                 /* if character quoted, */
  430.             *pp++ = (char)workch;    /*  include it literally */
  431.             quote = FALSE;
  432.         } else
  433.             switch (workch) {
  434.             case '/':             /* can assume -j flag not given */
  435.                 *pp = '\0';
  436.                 if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  437.                     return error;
  438.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  439.                 lastsemi = (char *)NULL; /* leave directory semi-colons alone */
  440.                 break;
  441.  
  442.             case ';':             /* VMS version (or DEC-20 attrib?) */
  443.                 lastsemi = pp;
  444.                 *pp++ = ';';      /* keep for now; remove VMS ";##" */
  445.                 break;            /*  later, if requested */
  446.  
  447.             case '\026':          /* control-V quote for special chars */
  448.                 quote = TRUE;     /* set flag for next character */
  449.                 break;
  450.  
  451. #ifdef MTS
  452.             case ' ':             /* change spaces to underscore under */
  453.                 *pp++ = '_';      /*  MTS; leave as spaces under Unix */
  454.                 break;
  455. #endif
  456.  
  457.             default:
  458.                 /* allow European characters in filenames: */
  459.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  460.                     *pp++ = (char)workch;
  461.             } /* end switch */
  462.  
  463.     } /* end while loop */
  464.  
  465.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  466.  
  467.     /* if not saving them, remove VMS version numbers (appended ";###") */
  468.     if (!G.V_flag && lastsemi) {
  469.         pp = lastsemi + 1;
  470.         while (isdigit((uch)(*pp)))
  471.             ++pp;
  472.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  473.             *lastsemi = '\0';
  474.     }
  475.  
  476. /*---------------------------------------------------------------------------
  477.     Report if directory was created (and no file to create:  filename ended
  478.     in '/'), check name to be sure it exists, and combine path and name be-
  479.     fore exiting.
  480.   ---------------------------------------------------------------------------*/
  481.  
  482.     if (G.filename[strlen(G.filename) - 1] == '/') {
  483.         checkdir(__G__ G.filename, GETPATH);
  484.         if (created_dir) {
  485.             if (QCOND2) {
  486.                 Info(slide, 0, ((char *)slide, "   creating: %s\n",
  487.                   G.filename));
  488.             }
  489.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  490.         }
  491.         return 2;   /* dir existed already; don't look for data to extract */
  492.     }
  493.  
  494.     if (*pathcomp == '\0') {
  495.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  496.           G.filename));
  497.         return 3;
  498.     }
  499.  
  500.     checkdir(__G__ pathcomp, APPEND_NAME);  /* returns 1 if truncated: care? */
  501.     checkdir(__G__ G.filename, GETPATH);
  502.  
  503.     return error;
  504.  
  505. } /* end function mapname() */
  506.  
  507.  
  508.  
  509.  
  510. #if 0  /*========== NOTES ==========*/
  511.  
  512.   extract-to dir:      a:path/
  513.   buildpath:           path1/path2/ ...   (NULL-terminated)
  514.   pathcomp:                filename
  515.  
  516.   mapname():
  517.     loop over chars in zipfile member name
  518.       checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  519.         (d:/tmp/unzip/)                    (disk:[tmp.unzip.)
  520.         (d:/tmp/unzip/jj/)                 (disk:[tmp.unzip.jj.)
  521.         (d:/tmp/unzip/jj/temp/)            (disk:[tmp.unzip.jj.temp.)
  522.     finally add filename itself and check for existence? (could use with rename)
  523.         (d:/tmp/unzip/jj/temp/msg.outdir)  (disk:[tmp.unzip.jj.temp]msg.outdir)
  524.     checkdir(name, GETPATH)     -->  copy path to name and free space
  525.  
  526. #endif /* 0 */
  527.  
  528.  
  529.  
  530.  
  531. /***********************/
  532. /* Function checkdir() */
  533. /***********************/
  534.  
  535. int checkdir(__G__ pathcomp, flag)
  536.     __GDEF
  537.     char *pathcomp;
  538.     int flag;
  539. /*
  540.  * returns:  1 - (on APPEND_NAME) truncated filename
  541.  *           2 - path doesn't exist, not allowed to create
  542.  *           3 - path doesn't exist, tried to create and failed; or
  543.  *               path exists and is not a directory, but is supposed to be
  544.  *           4 - path is too long
  545.  *          10 - can't allocate memory for filename buffers
  546.  */
  547. {
  548.     static int rootlen = 0;   /* length of rootpath */
  549.     static char *rootpath;    /* user's "extract-to" directory */
  550.     static char *buildpath;   /* full path (so far) to extracted file */
  551.     static char *end;         /* pointer to end of buildpath ('\0') */
  552.  
  553. #   define FN_MASK   7
  554. #   define FUNCTION  (flag & FN_MASK)
  555.  
  556.  
  557.  
  558. /*---------------------------------------------------------------------------
  559.     APPEND_DIR:  append the path component to the path being built and check
  560.     for its existence.  If doesn't exist and we are creating directories, do
  561.     so for this one; else signal success or error as appropriate.
  562.   ---------------------------------------------------------------------------*/
  563.  
  564.     if (FUNCTION == APPEND_DIR) {
  565.         int too_long = FALSE;
  566. #ifdef SHORT_NAMES
  567.         char *old_end = end;
  568. #endif
  569.  
  570.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  571.         while ((*end = *pathcomp++) != '\0')
  572.             ++end;
  573. #ifdef SHORT_NAMES   /* path components restricted to 14 chars, typically */
  574.         if ((end-old_end) > FILENAME_MAX)  /* GRR:  proper constant? */
  575.             *(end = old_end + FILENAME_MAX) = '\0';
  576. #endif
  577.  
  578.         /* GRR:  could do better check, see if overrunning buffer as we go:
  579.          * check end-buildpath after each append, set warning variable if
  580.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  581.          * appending.  Clear variable when begin new path. */
  582.  
  583.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  584.             too_long = TRUE;                /* check if extracting directory? */
  585.         /* for AOS/VS, try to create so as to not use searchlist: */
  586.         if ( /*stat(buildpath, &G.statbuf)*/ 1) {
  587.             if (!G.create_dirs) { /* told not to create (freshening) */
  588.                 free(buildpath);
  589.                 return 2;         /* path doesn't exist:  nothing to do */
  590.             }
  591.             if (too_long) {
  592.                 Info(slide, 1, ((char *)slide,
  593.                   "checkdir error:  path too long: %s\n", buildpath));
  594.                 free(buildpath);
  595.                 return 4;         /* no room for filenames:  fatal */
  596.             }
  597.             /* create the directory */
  598.             if (zvs_credir(buildpath,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1) == -1)
  599.             {
  600.                 Info(slide, 1, ((char *)slide,
  601.                   "checkdir error:  can't create %s\n\
  602.                  unable to process %s.\n", buildpath, G.filename));
  603.                 free(buildpath);
  604.                 return 3;      /* path didn't exist, tried to create, failed */
  605.             }
  606.             created_dir = TRUE;
  607.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  608.             Info(slide, 1, ((char *)slide, "checkdir error:  %s exists but is not directory\n\
  609.                  unable to process %s.\n", buildpath, G.filename));
  610.             free(buildpath);
  611.             return 3;          /* path existed but wasn't dir */
  612.         }
  613.         if (too_long) {
  614.             Info(slide, 1, ((char *)slide,
  615.               "checkdir error:  path too long: %s\n", buildpath));
  616.             free(buildpath);
  617.             return 4;         /* no room for filenames:  fatal */
  618.         }
  619.         *end++ = '/';
  620.         *end = '\0';
  621.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  622.         return 0;
  623.  
  624.     } /* end if (FUNCTION == APPEND_DIR) */
  625.  
  626. /*---------------------------------------------------------------------------
  627.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  628.     buildpath.
  629.   ---------------------------------------------------------------------------*/
  630.  
  631.     if (FUNCTION == GETPATH) {
  632.         strcpy(pathcomp, buildpath);
  633.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  634.         free(buildpath);
  635.         buildpath = end = (char *)NULL;
  636.         return 0;
  637.     }
  638.  
  639. /*---------------------------------------------------------------------------
  640.     APPEND_NAME:  assume the path component is the filename; append it and
  641.     return without checking for existence.
  642.   ---------------------------------------------------------------------------*/
  643.  
  644.     if (FUNCTION == APPEND_NAME) {
  645. #ifdef SHORT_NAMES
  646.         char *old_end = end;
  647. #endif
  648.  
  649.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  650.         while ((*end = *pathcomp++) != '\0') {
  651.             ++end;
  652. #ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */
  653.             if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */
  654.                 *(end = old_end + FILENAME_MAX) = '\0';
  655. #endif
  656.             if ((end-buildpath) >= FILNAMSIZ) {
  657.                 *--end = '\0';
  658.                 Info(slide, 1, ((char *)slide,
  659.                   "checkdir warning:  path too long; truncating\n\
  660.                    %s\n                -> %s\n", G.filename, buildpath));
  661.                 return 1;   /* filename truncated */
  662.             }
  663.         }
  664.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  665.         return 0;  /* could check for existence here, prompt for new name... */
  666.     }
  667.  
  668. /*---------------------------------------------------------------------------
  669.     INIT:  allocate and initialize buffer space for the file currently being
  670.     extracted.  If file was renamed with an absolute path, don't prepend the
  671.     extract-to path.
  672.   ---------------------------------------------------------------------------*/
  673.  
  674. /* GRR:  for VMS and TOPS-20, add up to 13 to strlen */
  675.  
  676.     if (FUNCTION == INIT) {
  677.         Trace((stderr, "initializing buildpath to "));
  678.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) ==
  679.             (char *)NULL)
  680.             return 10;
  681.         if ((rootlen > 0) && !renamed_fullpath) {
  682.             strcpy(buildpath, rootpath);
  683.             end = buildpath + rootlen;
  684.         } else {
  685.             *buildpath = '\0';
  686.             end = buildpath;
  687.         }
  688.         Trace((stderr, "[%s]\n", buildpath));
  689.         return 0;
  690.     }
  691.  
  692. /*---------------------------------------------------------------------------
  693.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  694.     sary; else assume it's a zipfile member and return.  This path segment
  695.     gets used in extracting all members from every zipfile specified on the
  696.     command line.
  697.   ---------------------------------------------------------------------------*/
  698.  
  699. #if (!defined(SFX) || defined(SFX_EXDIR))
  700.     if (FUNCTION == ROOT) {
  701.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  702.         if (pathcomp == (char *)NULL) {
  703.             rootlen = 0;
  704.             return 0;
  705.         }
  706.         if ((rootlen = strlen(pathcomp)) > 0) {
  707.             if (pathcomp[rootlen-1] == '/') {
  708.                 pathcomp[--rootlen] = '\0';
  709.             }
  710.             if (rootlen > 0 && (stat(pathcomp, &G.statbuf) ||
  711.                 !S_ISDIR(G.statbuf.st_mode)))       /* path does not exist */
  712.             {
  713.                 if (!G.create_dirs /* || iswild(pathcomp) */ ) {
  714.                     rootlen = 0;
  715.                     return 2;   /* skip (or treat as stored file) */
  716.                 }
  717.                 /* create the directory (could add loop here to scan pathcomp
  718.                  * and create more than one level, but why really necessary?) */
  719.                 if (zvs_credir(pathcomp,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1)
  720.                     == -1)
  721.                 {
  722.                     Info(slide, 1, ((char *)slide,
  723.                       "checkdir:  can't create extraction directory: %s\n",
  724.                       pathcomp));
  725.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  726.                     return 3;  /* failed:  file exists, or 2+ levels required */
  727.                 }
  728.             }
  729.             if ((rootpath = (char *)malloc(rootlen+2)) == (char *)NULL) {
  730.                 rootlen = 0;
  731.                 return 10;
  732.             }
  733.             strcpy(rootpath, pathcomp);
  734.             rootpath[rootlen++] = '/';
  735.             rootpath[rootlen] = '\0';
  736.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  737.         }
  738.         return 0;
  739.     }
  740. #endif /* !SFX || SFX_EXDIR */
  741.  
  742. /*---------------------------------------------------------------------------
  743.     END:  free rootpath, immediately prior to program exit.
  744.   ---------------------------------------------------------------------------*/
  745.  
  746.     if (FUNCTION == END) {
  747.         Trace((stderr, "freeing rootpath\n"));
  748.         if (rootlen > 0)
  749.             free(rootpath);
  750.         return 0;
  751.     }
  752.  
  753.     return 99;  /* should never reach */
  754.  
  755. } /* end function checkdir() */
  756.  
  757.  
  758.  
  759.  
  760.  
  761. #ifdef MORE
  762.  
  763. /**************************/
  764. /* Function screenlines() */
  765. /**************************/
  766.  
  767. int screenlines()
  768. {
  769.     char *envptr, *getenv();
  770.     int n;
  771.  
  772.     /* GRR:  this is overly simplistic; should use winsize struct and
  773.      * appropriate TIOCGWINSZ ioctl(), assuming exists on enough systems
  774.      */
  775.     envptr = getenv("LINES");
  776.     if (envptr == (char *)NULL || (n = atoi(envptr)) < 5)
  777.         return 24;   /* VT-100 assumed to be minimal hardware */
  778.     else
  779.         return n;
  780. }
  781.  
  782. #endif /* MORE */
  783.  
  784.  
  785.  
  786.  
  787.  
  788. /****************************/
  789. /* Function close_outfile() */
  790. /****************************/
  791.  
  792. void close_outfile(__G)    /* GRR: change to return PK-style warning level */
  793.     __GDEF
  794. {
  795.  
  796. /*---------------------------------------------------------------------------
  797.     If symbolic links are supported, allocate a storage area, put the uncom-
  798.     pressed "data" in it, and create the link.  Since we know it's a symbolic
  799.     link to start with, we shouldn't have to worry about overflowing unsigned
  800.     ints with unsigned longs.
  801.   ---------------------------------------------------------------------------*/
  802.  
  803. #ifdef SYMLINKS
  804.     if (G.symlnk) {
  805.         unsigned ucsize = (unsigned)G.lrec.ucsize;
  806.         char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);
  807.  
  808.         fclose(G.outfile);                      /* close "data" file... */
  809.         G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */
  810.         if (!linktarget || fread(linktarget, 1, ucsize, G.outfile) !=
  811.                            (int)ucsize)
  812.         {
  813.             Info(slide, 0x201, ((char *)slide,
  814.               "warning:  symbolic link (%s) failed\n", G.filename));
  815.             if (linktarget)
  816.                 free(linktarget);
  817.             fclose(G.outfile);
  818.             return;
  819.         }
  820.         fclose(G.outfile);                  /* close "data" file for good... */
  821.         unlink(G.filename);                 /* ...and delete it */
  822.         linktarget[ucsize] = '\0';
  823.         Info(slide, 0, ((char *)slide, "-> %s ", linktarget));
  824.         if (symlink(linktarget, G.filename))  /* create the real link */
  825.             perror("symlink error");
  826.         free(linktarget);
  827.         return;                             /* can't set time on symlinks */
  828.     }
  829. #endif /* SYMLINKS */
  830.  
  831.     fclose(G.outfile);
  832.  
  833. /*---------------------------------------------------------------------------
  834.     Change the file permissions from default ones to those stored in the
  835.     zipfile.
  836.   ---------------------------------------------------------------------------*/
  837.  
  838. #ifndef NO_CHMOD
  839.     if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  840.         perror("chmod (file attributes) error");
  841. #endif
  842.  
  843. /*---------------------------------------------------------------------------
  844.     AOS/VS only allows setting file times at creation but has its own permis-
  845.     sions scheme which is better invoked here if the necessary information
  846.     was in fact stored.  In theory, we should look through an entire series
  847.     of extra fields that might exist for the same file, but we're not going
  848.     to bother.  If we set up other types of extra fields, or if we run into
  849.     other environments that add their own stuff to existing entries in ZIP
  850.     files, we'll have to.  NOTE:  already copied extra-field stuff into
  851.     zzextrafld structure when file was created.
  852.   ---------------------------------------------------------------------------*/
  853.  
  854.     if (G.extra_field != NULL) {
  855.         if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  856.                     sizeof(zzextrafld.extra_header_id))  &&
  857.             !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel,
  858.                     sizeof(zzextrafld.extra_sentinel))  &&
  859.             zzextrafld.fstat_packet.norm_fstat_packet.styp_type != $FLNK)
  860.             /* (AOS/VS links don't have ACLs) */
  861.         {
  862.             /* vs_path was set (in this case) when we created the file */
  863.             if (sys_sacl(vs_path, zzextrafld.aclbuf)) {
  864.                 Info(slide, 0x201, ((char *)slide,
  865.                   "error: can't set ACL for %s\n", G.filename));
  866.                 perror("sys_sacl()");
  867.             }
  868.         }
  869.     }
  870. } /* end function close_outfile() */
  871.  
  872.  
  873.  
  874.  
  875. #ifndef SFX
  876.  
  877. /************************/
  878. /*  Function version()  */
  879. /************************/
  880.  
  881. void version(__G)
  882.     __GDEF
  883. {
  884. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE) || defined(NetBSD)
  885.     char buf1[40];
  886. #if defined(CRAY) || defined(NX_CURRENT_COMPILER_RELEASE)
  887.     char buf2[40];
  888. #endif
  889. #endif
  890.  
  891.     /* Pyramid, NeXT have problems with huge macro expansion, too:  no Info() */
  892.     sprintf((char *)slide, LoadFarString(CompiledWith),
  893.  
  894. #ifdef __GNUC__
  895. #  ifdef NX_CURRENT_COMPILER_RELEASE
  896.       (sprintf(buf1, "NeXT DevKit %d.%02d ", NX_CURRENT_COMPILER_RELEASE/100,
  897.         NX_CURRENT_COMPILER_RELEASE%100), buf1),
  898.       (strlen(__VERSION__) > 8)? "(gcc)" :
  899.         (sprintf(buf2, "(gcc %s)", __VERSION__), buf2),
  900. #  else
  901.       "gcc ", __VERSION__,
  902. #  endif
  903. #else
  904. #  if defined(CRAY) && defined(_RELEASE)
  905.       "cc ", (sprintf(buf1, "version %d", _RELEASE), buf1),
  906. #  else
  907. #  ifdef __VERSION__
  908.       "cc ", __VERSION__,
  909. #  else
  910.       "cc", "",
  911. #  endif
  912. #  endif
  913. #endif
  914.  
  915.       "Unix",
  916.  
  917. #if defined(sgi) || defined(__sgi)
  918.       " (Silicon Graphics IRIX)",
  919. #else
  920. #ifdef sun
  921. #  ifdef sparc
  922. #    ifdef __SVR4
  923.       " (Sun Sparc/Solaris)",
  924. #    else /* may or may not be SunOS */
  925.       " (Sun Sparc)",
  926. #    endif
  927. #  else
  928. #  if defined(sun386) || defined(i386)
  929.       " (Sun 386i)",
  930. #  else
  931. #  if defined(mc68020) || defined(__mc68020__)
  932.       " (Sun 3)",
  933. #  else /* mc68010 or mc68000:  Sun 2 or earlier */
  934.       " (Sun 2)",
  935. #  endif
  936. #  endif
  937. #  endif
  938. #else
  939. #ifdef __hpux
  940.       " (HP/UX)",
  941. #else
  942. #ifdef __osf__
  943.       " (DEC OSF/1)",
  944. #else
  945. #ifdef _AIX
  946.       " (IBM AIX)",
  947. #else
  948. #ifdef aiws
  949.       " (IBM RT/AIX)",
  950. #else
  951. #if defined(CRAY) || defined(cray)
  952. #  ifdef _UNICOS
  953.       (sprintf(buf2, " (Cray UNICOS release %d)", _UNICOS), buf2),
  954. #  else
  955.       " (Cray UNICOS)",
  956. #  endif
  957. #else
  958. #if defined(uts) || defined(UTS)
  959.       " (Amdahl UTS)",
  960. #else
  961. #ifdef NeXT
  962. #  ifdef mc68000
  963.       " (NeXTStep/black)",
  964. #  else
  965.       " (NeXTStep for Intel)",
  966. #  endif
  967. #else              /* the next dozen or so are somewhat order-dependent */
  968. #ifdef LINUX
  969. #  ifdef __ELF__
  970.       " (Linux ELF)",
  971. #  else
  972.       " (Linux a.out)",
  973. #  endif
  974. #else
  975. #ifdef MINIX
  976.       " (Minix)",
  977. #else
  978. #ifdef M_UNIX
  979.       " (SCO Unix)",
  980. #else
  981. #ifdef M_XENIX
  982.       " (SCO Xenix)",
  983. #else
  984. #ifdef __NetBSD__
  985. #  ifdef NetBSD0_8
  986.       (sprintf(buf1, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')), buf1),
  987. #  else
  988. #  ifdef NetBSD0_9
  989.       (sprintf(buf1, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')), buf1),
  990. #  else
  991. #  ifdef NetBSD1_0
  992.       (sprintf(buf1, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')), buf1),
  993. #  else
  994.       (BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
  995. #  endif
  996. #  endif
  997. #  endif
  998. #else
  999. #ifdef __FreeBSD__
  1000.       (BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
  1001. #else
  1002. #ifdef __bsdi__
  1003.       (BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
  1004. #else
  1005. #ifdef __386BSD__
  1006.       (BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
  1007. #else
  1008. #if defined(i486) || defined(__i486) || defined(__i486__)
  1009.       " (Intel 486)",
  1010. #else
  1011. #if defined(i386) || defined(__i386) || defined(__i386__)
  1012.       " (Intel 386)",
  1013. #else
  1014. #ifdef pyr
  1015.       " (Pyramid)",
  1016. #else
  1017. #ifdef ultrix
  1018. #  ifdef mips
  1019.       " (DEC/MIPS)",
  1020. #  else
  1021. #  ifdef vax
  1022.       " (DEC/VAX)",
  1023. #  else /* __alpha? */
  1024.       " (DEC/Alpha)",
  1025. #  endif
  1026. #  endif
  1027. #else
  1028. #ifdef gould
  1029.       " (Gould)",
  1030. #else
  1031. #ifdef MTS
  1032.       " (MTS)",
  1033. #else
  1034. #ifdef __convexc__
  1035.       " (Convex)",
  1036. #else
  1037.       "",
  1038. #endif /* Convex */
  1039. #endif /* MTS */
  1040. #endif /* Gould */
  1041. #endif /* DEC */
  1042. #endif /* Pyramid */
  1043. #endif /* 386 */
  1044. #endif /* 486 */
  1045. #endif /* 386BSD */
  1046. #endif /* BSDI BSD/386 */
  1047. #endif /* NetBSD */
  1048. #endif /* FreeBSD */
  1049. #endif /* SCO Xenix */
  1050. #endif /* SCO Unix */
  1051. #endif /* Minix */
  1052. #endif /* Linux */
  1053. #endif /* NeXT */
  1054. #endif /* Amdahl */
  1055. #endif /* Cray */
  1056. #endif /* RT/AIX */
  1057. #endif /* AIX */
  1058. #endif /* OSF/1 */
  1059. #endif /* HP/UX */
  1060. #endif /* Sun */
  1061. #endif /* SGI */
  1062.  
  1063. #ifdef __DATE__
  1064.       " on ", __DATE__
  1065. #else
  1066.       "", ""
  1067. #endif
  1068.     );
  1069.  
  1070.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  1071.  
  1072. } /* end function version() */
  1073.  
  1074. #endif /* !SFX */
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080. /* ===================================================================
  1081.  * ZVS_CREATE()
  1082.  * Function to create a file with specified times.  The times should be sent
  1083.  * as long ints in DG time format; use -1 to set to the current times.  You
  1084.  * may also specify a pointer to the ACL, the file type (see PARU.H, and do
  1085.  * not specify dirs or links), the element size, and the max index level.
  1086.  * For all of these parameters you may use -1 to specify the default.
  1087.  *
  1088.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1089.  *
  1090.  *    HISTORY:
  1091.  *        15-dec-93 dbl
  1092.  *        31-may-94 dbl: added call to convert pathname to AOS/VS
  1093.  *
  1094.  *
  1095.  */
  1096.  
  1097. int zvs_create(char *fname, long cretim, long modtim, long acctim, char *pacl,
  1098.                int ftyp, int eltsize, int maxindlev)
  1099. {
  1100.     P_CREATE    pcr_stru;
  1101.     P_CTIM      pct_stru;
  1102.  
  1103.     pcr_stru.cftyp_format = 0;           /* unspecified record format */
  1104.     if (ftyp == -1)                      /* default file type to UNX */
  1105.         pcr_stru.cftyp_entry = $FUNX;
  1106.     else
  1107.         pcr_stru.cftyp_entry = ftyp;
  1108.     pcr_stru.ctim = &pct_stru;
  1109.     pcr_stru.cacp = pacl;
  1110.     pcr_stru.cdel = eltsize;
  1111.     pcr_stru.cmil = maxindlev;
  1112.  
  1113.     pct_stru.tcth.long_time = cretim;
  1114.     pct_stru.tath.long_time = acctim;
  1115.     pct_stru.tmth.long_time = modtim;
  1116.  
  1117.     return (sys_create(ux_to_vs_name(Vs_path, fname), &pcr_stru));
  1118.  
  1119. } /* end zvs_create() */
  1120.  
  1121.  
  1122.  
  1123. /* ===================================================================
  1124.  * ZVS_CREDIR()
  1125.  * Function to create a dir as specified.  The times should be sent
  1126.  * as long ints in DG time format; use -1 to set to the current times.  You
  1127.  * may also specify a pointer to the ACL, the file type (either $FDIR or $FCPD; see PARU.H),
  1128.  * the max # blocks (if a CPD), the hash frame size, and the max index level.
  1129.  * For all of these parameters (except for the CPD's maximum blocks),
  1130.  * you may use -1 to specify the default.
  1131.  *
  1132.  * (The System Call Dictionary says both that you may specify a
  1133.  * maximum-index-level value up to the maximum, with 0 for a contiguous
  1134.  * directory, and that 3 is always used for this whatever you specify.)
  1135.  *
  1136.  * If you specify anything other than CPD for the file type, DIR will
  1137.  * be used.
  1138.  *
  1139.  * Returns 0 if no error, or the error code returned by ?CREATE.
  1140.  *
  1141.  *    HISTORY:
  1142.  *        1-jun-94 dbl
  1143.  *
  1144.  *
  1145.  */
  1146.  
  1147. int zvs_credir(char *dname, long cretim, long modtim, long acctim, char *pacl, int ftyp, long maxblocks, int hashfsize, int maxindlev)
  1148. {
  1149.     P_CREATE_DIR    pcr_stru;
  1150.     P_CTIM          pct_stru;
  1151.  
  1152.     if (ftyp != $FCPD)                      /* default file type to UNX */
  1153.         pcr_stru.cftyp_entry = $FDIR;
  1154.     else
  1155.     {
  1156.         pcr_stru.cftyp_entry = ftyp;
  1157.         pcr_stru.cmsh = maxblocks;
  1158.     }
  1159.  
  1160.     pcr_stru.ctim = &pct_stru;
  1161.     pcr_stru.cacp = pacl;
  1162.     pcr_stru.chfs = hashfsize;
  1163.     pcr_stru.cmil = maxindlev;
  1164.  
  1165.     pct_stru.tcth.long_time = cretim;
  1166.     pct_stru.tath.long_time = acctim;
  1167.     pct_stru.tmth.long_time = modtim;
  1168.  
  1169.     return (sys_create(ux_to_vs_name(Vs_path, dname), &pcr_stru));
  1170.  
  1171. } /* end zvs_credir() */
  1172.  
  1173.  
  1174.  
  1175. /* ===================================================================
  1176.  * UX_TO_VS_NAME() - makes a somewhat dumb pass at converting a Unix
  1177.  *           filename to an AOS/VS filename.  This should
  1178.  *           be just about adequate to handle the results
  1179.  *           of similarly-simple AOS/VS-to-Unix conversions
  1180.  *           in the ZIP program.  It does not guarantee a
  1181.  *           legal AOS/VS filename for every Unix filename;
  1182.  *           conspicuous examples would be names with
  1183.  *           embedded ./ and ../ (which will receive no
  1184.  *           special treatment).
  1185.  *
  1186.  *       RETURNS: pointer to the result (which is an input parameter)
  1187.  *
  1188.  *       NOTE: calling code is responsible for making sure
  1189.  *           the output buffer is big enough!
  1190.  *
  1191.  *       HISTORY:
  1192.  *           31-may-94 dbl
  1193.  *
  1194.  */
  1195. char *ux_to_vs_name(char *outname, char *inname)
  1196. {
  1197.     char *ip=inname, *op=outname;
  1198.  
  1199.  
  1200.     if (ip[0] == '.') {
  1201.         if (ip[1] == '/') {
  1202.             *(op++) = '=';
  1203.             ip += 2;
  1204.         } else if (ip[1] == '.'  &&  ip[2] == '/') {
  1205.             *(op++) = '^';
  1206.             ip += 3;
  1207.         }
  1208.     }
  1209.  
  1210.     do {
  1211.         if (*ip == '/')
  1212.             *(op++) = ':';
  1213.         else if (strchr(
  1214.            "0123456789_$?.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  1215.            *ip) != NULL)
  1216.         {
  1217.             *(op++) = *ip;
  1218.         } else
  1219.             *(op++) = '?';
  1220.  
  1221.     } while (*(ip++) != '\0');
  1222.  
  1223.     return outname;
  1224.  
  1225. } /* end ux_to_vs_name() */
  1226.  
  1227.  
  1228.  
  1229. /* =================================================================== */
  1230.  
  1231. /* DGDATE
  1232.    Two functions do encode/decode dates in DG system format.
  1233.  
  1234.    Usage:
  1235.     long value,year,month,day;
  1236.  
  1237.     value=dgdate(month,day,year);
  1238.     undgdate(value,&month,&day,&year);   [GRR:  not used in UnZip: removed]
  1239.  
  1240.    Notes:
  1241.  
  1242.    1. DG date functions only work on dates within the range
  1243.       Jan 1, 1968 through Dec 31, 2099.  I have tested these
  1244.       functions through the same range with exact agreement.
  1245.       For dates outside of that range, the DG system calls
  1246.       may return different values than these functions.
  1247.  
  1248.    2. dgundate() accepts values between 0 and 48213 inclusive.
  1249.       These correspond to 12/31/1967 and 12/31/2099.
  1250.  
  1251.    3. Both functions assume the data is in the native OS byte
  1252.       order.  So if you're reading or writing these fields from
  1253.       a file that has been passed between AOS/VS and PC-DOS you
  1254.       will need to swap byte order.
  1255.  
  1256.    4. With reference to byte order, the entire range of values
  1257.       supported by these functions will fit into an unsigned
  1258.       short int.  In most cases the input or output will be
  1259.       in that variable type.  You are better off casting the
  1260.       value to/from unsigned short so you only need to concern
  1261.       yourself with swapping two bytes instead of four.
  1262.  
  1263.   Written by: Stanley J. Gula
  1264.               US&T, Inc.
  1265.               529 Main Street, Suite 1
  1266.               Indian Orchard, MA 01151
  1267.               (413)-543-3672
  1268.               Copyright (c) 1990 US&T, Inc.
  1269.               All rights reserved.
  1270.  
  1271.               I hereby release these functions into the public
  1272.               domain.  You may use these routines freely as long
  1273.               as the US&T copyright remains intact in the source
  1274.               code.
  1275.  
  1276.               Stanley J. Gula     July 24, 1990
  1277. */
  1278.  
  1279. long motable[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
  1280.  
  1281. long yrtable[132]={
  1282.       366,  731, 1096, 1461, 1827, 2192, 2557, 2922, 3288, 3653,
  1283.      4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940, 7305,
  1284.      7671, 8036, 8401, 8766, 9132, 9497, 9862,10227,10593,10958,
  1285.     11323,11688,12054,12419,12784,13149,13515,13880,14245,14610,
  1286.     14976,15341,15706,16071,16437,16802,17167,17532,17898,18263,
  1287.     18628,18993,19359,19724,20089,20454,20820,21185,21550,21915,
  1288.     22281,22646,23011,23376,23742,24107,24472,24837,25203,25568,
  1289.     25933,26298,26664,27029,27394,27759,28125,28490,28855,29220,
  1290.     29586,29951,30316,30681,31047,31412,31777,32142,32508,32873,
  1291.     33238,33603,33969,34334,34699,35064,35430,35795,36160,36525,
  1292.     36891,37256,37621,37986,38352,38717,39082,39447,39813,40178,
  1293.     40543,40908,41274,41639,42004,42369,42735,43100,43465,43830,
  1294.     44196,44561,44926,45291,45657,46022,46387,46752,47118,47483,
  1295.     47848,48213};
  1296.  
  1297. /* Given y,m,d return # of days since 12/31/67 */
  1298. long int dgdate(short mm, short dd, short yy)
  1299. {
  1300.     long int temp;
  1301.     short ytmp;
  1302.  
  1303.     if (mm<1 || mm>12 || dd<1 || dd>31 || yy<1968 || yy>2099)
  1304.         return 0L;
  1305.  
  1306.     /* Figure in whole years since 1968 + whole months plus days */
  1307.     temp=365L*(long)(yy-1968) + motable[mm-1] + (long)dd;
  1308.  
  1309.     /* Adjust for leap years - note we don't account for skipped leap
  1310.        year in years divisible by 1000 but not by 4000.  We're correct
  1311.        through the year 2099 */
  1312.     temp+=(yy-1965)/4;
  1313.  
  1314.     /* Correct for this year */
  1315.     /* In leap years, if date is 3/1 or later, bump */
  1316.     if ((yy%4==0) && (mm>2))
  1317.         temp++;
  1318.  
  1319.     return temp;
  1320. }
  1321.